package com.cms.skin

import com.alibaba.android.arouter.facade.annotation.Route
import com.android.baselibrary.arouter.ArouterContains
import com.android.baselibrary.base.BaseActivity
import com.cms.skin.databinding.ActivitySkinMainBinding

@Route(path = ArouterContains.ROOM_SKIN)
class SkinMainActivity : BaseActivity<ActivitySkinMainBinding>() {
    override fun getLayoutId(): Int = R.layout.activity_skin_main

    override fun initView() {

             mBinding.rg.check(when(SkinSharePreference.instance?.getSkinPath()){
                 "${baseContext.cacheDir}/blue_skinresource-debug.apk" -> R.id.rb_blue
                 "${baseContext.cacheDir}/green_skinresource-debug.apk" -> R.id.rb_green
                 "${baseContext.cacheDir}/orange_skinresource-debug.apk" -> R.id.rb_orange
                 "${baseContext.cacheDir}/red_skinresource-debug.apk" -> R.id.rb_red

                 else ->R.id.rb_default
             })
    }

    override fun initListener() {
        mBinding.rg.setOnCheckedChangeListener { group, checkedId ->
            when(checkedId){
                R.id.rb_blue->{
                    val skinPkg: String ="${baseContext.cacheDir}/blue_skinresource-debug.apk"
                    SkinManager.instance.loadSkinPath(skinPkg)
                }
                R.id.rb_default->{
                    SkinManager.instance.loadSkinPath(null)
                }
                R.id.rb_green ->{
                    val skinPkg: String ="${baseContext.cacheDir}/green_skinresource-debug.apk"
                    SkinManager.instance.loadSkinPath(skinPkg)
                }
                R.id.rb_orange->{
                    val skinPkg: String ="${baseContext.cacheDir}/orange_skinresource-debug.apk"
                    SkinManager.instance.loadSkinPath(skinPkg)
                }
                R.id.rb_red ->{
                    val skinPkg: String ="${baseContext.cacheDir}/red_skinresource-debug.apk"
                    SkinManager.instance.loadSkinPath(skinPkg)
                }
            }
        }
    }

}